let fs = require('fs');
let path = require('path');

// console.log("当前路径",__dirname);
// console.log("当前文件",__filename)
// D:\temp\1803a\node_demo
// D:\temp\1803a    arr.html

var mypp = path.resolve(__dirname,'../arr.html');


// \temp\1803a\node_demo\arr.html
// fs.readFile('文件名',获取到数据后的处理函数)
// fs.writeFile('文件名',文件内容,'写完之后干什么')

fs.readFile(mypp,function(err,data){
	if(err) console.error(err);
	console.log(data.toString());
});

var users = [
{name:'张三',age:18,sex:'男'},
{name:'魏红',age:19,sex:'女'},
{name:'建国',age:48,sex:'男'},
{name:'二狗',age:15,sex:'男'},
];

fs.writeFile(
	path.resolve(__dirname,'../mytest.json'),
	JSON.stringify(users,null,4),
	function (err,a) {
		console.log(err,a);
	});